package com.xy.netty.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

public class DemoSocketServerHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//        System.out.println("Client Address ========= " + ctx.channel().remoteAddress());
//        ctx.channel().writeAndFlush("from server:" + UUID.randomUUID());
        System.out.println(msg);
        System.out.println("-----------");
        ctx.channel().writeAndFlush("<div>aaaa</div>");
        ctx.fireChannelActive();
        TimeUnit.MILLISECONDS.sleep(500);
    }


    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}
